﻿using System;
using Tao.OpenGl;

namespace Aeon.Framework.Objects
{

/// <summary>
/// Plane primitive class.
/// Uses up to 1 color and texture, for front face.
/// 
/// </summary>
public class Plane : ObjectBase
    {
    // --- Attributes:
    
    private Single dimensionD;      // Plane half depth.
    private Single dimensionH;      // Plane half height.

    // --- Constructor:

    /// <summary>
    /// Square plane constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="size"> Plane dimension. </param>
    public Plane(String key, Position origin, Orientation angle, Single size)
        : this(key, origin, angle, size, size, AeonMaterials.Default) { }

    /// <summary>
    /// Custom rectangular plane constructor.
    /// 
    /// </summary>
    /// <param name="key"> Unique identifier. </param>
    /// <param name="origin"> Object origin.  </param>
    /// <param name="angle"> Object orientation. </param>
    /// <param name="length"> Plane size on X. </param>
    /// <param name="depth"> Plane size on Z. </param>
    /// <param name="material"> Plane material. </param>
    public Plane(String key, Position origin, Orientation angle, Single lenght, Single depth, AeonMaterial material)
        : base(key,origin,angle,material)
        {
        dimensionH = lenght/2;
        dimensionD = depth/2;
        }

    // --- External Methods:

    public override void Draw()
        {
        Gl.glTranslated(origin.xPos,origin.yPos,origin.zPos);
        Gl.glRotated(angle.xAng,1,0,0);
        Gl.glRotated(angle.yAng,0,1,0);
        Gl.glRotated(angle.zAng,0,0,1);

        Gl.glColor4f(material.Color.R, material.Color.G, material.Color.B, material.Color.A);
        material.Texture.Bind();
        
        // Face Up
        Gl.glBegin(Gl.GL_QUADS);        
        Gl.glNormal3i(0,1,0);
        
        Gl.glTexCoord2f(1.0f, 0.0f);
        Gl.glVertex3f(dimensionD, 0, -dimensionH);
        Gl.glTexCoord2f(0.0f, 0.0f);
        Gl.glVertex3f(-dimensionD, 0, -dimensionH);
        Gl.glTexCoord2f(0.0f, 1.0f);
        Gl.glVertex3f(-dimensionD, 0, dimensionH);
        Gl.glTexCoord2f(1.0f, 1.0f);
        Gl.glVertex3f(dimensionD, 0, dimensionH);

        Gl.glEnd();
        }

    }


}